package me.kuye.jkuye.config;

import java.util.HashMap;
import java.util.Map;

import me.kuye.jkuye.core.Const;
import me.kuye.jkuye.render.ViewType;
import me.kuye.jkuye.token.ITokenCache;

public class Constants {
	private String fileRenderPath;
	private Boolean devMode = false;
	private String encoding = Const.DEFAULT_ENCODING;
	private ITokenCache tokenCache;
	private String uploadedFileSaveDirectory;
	private int maxPostSize = Const.DEFAULT_MAX_POST_SIZE;
	private ViewType viewType = Const.VIEW_TYPE;
	private int freemarkerTemplateUpdateDelay = Const.DEFAULT_FREEMARKER_TEMPLATE_UPDATE_DELAY;
	private String jspViewExtension = Const.DEFAULT_JSP_EXTENSION;
	private String freeMarkerViewExtension = Const.DEFAULT_FREE_MARKER_EXTENSION;
	private String velocityViewExtension = Const.DEFAULT_VELOCITY_EXTENSION;
	private Map<Integer, String> errorViewMapping = new HashMap<Integer, String>();
	private String urlParaSeparator = Const.URL_PARA_SEPARATOR;

	public void setDevMode(boolean devMode) {
		this.devMode = devMode;
	}

	public boolean getDevMode() {
		return devMode;
	}

	public void setEncoding(String encoding) {
		this.encoding = encoding;
	}

	public String getEncoding() {
		return encoding;
	}

	public ITokenCache getTokenCache() {
		return tokenCache;
	}

	public void setTokenCache(ITokenCache tokenCache) {
		this.tokenCache = tokenCache;
	}

	public void setDevMode(Boolean devMode) {
		this.devMode = devMode;
	}

	public String getUploadedFileSaveDirectory() {
		return uploadedFileSaveDirectory;
	}

	public void setUploadedFileSaveDirectory(String uploadedFileSaveDirectory) {
		this.uploadedFileSaveDirectory = uploadedFileSaveDirectory;
	}

	public int getMaxPostSize() {
		return maxPostSize;
	}

	public void setMaxPostSize(int maxPostSize) {
		this.maxPostSize = maxPostSize;
	}

	public ViewType getViewType() {
		return viewType;
	}

	public void setViewType(ViewType viewType) {
		this.viewType = viewType;
	}

	public int getFreemarkerTemplateUpdateDelay() {
		return freemarkerTemplateUpdateDelay;
	}

	public void setFreemarkerTemplateUpdateDelay(int freemarkerTemplateUpdateDelay) {
		this.freemarkerTemplateUpdateDelay = freemarkerTemplateUpdateDelay;
	}

	public String getFileRenderPath() {
		return fileRenderPath;
	}

	public void setFileRenderPath(String fileRenderPath) {
		this.fileRenderPath = fileRenderPath;
	}

	public String getUrlParaSeparator() {
		return urlParaSeparator;
	}

	/*
	 * 服务器端模板的文件后缀
	 * 
	 */
	public String getJspViewExtension() {
		return jspViewExtension;
	}

	public void setJspViewExtension(String jspViewExtension) {
		this.jspViewExtension = jspViewExtension.startsWith(".") ? jspViewExtension : "." + jspViewExtension;
	}

	public String getFreeMarkerViewExtension() {
		return freeMarkerViewExtension;
	}

	public void setFreeMarkerViewExtension(String freeMarkerViewExtension) {
		this.freeMarkerViewExtension = freeMarkerViewExtension.startsWith(".") ? freeMarkerViewExtension
				: "." + freeMarkerViewExtension;
	}

	public String getVelocityViewExtension() {
		return velocityViewExtension;
	}

	public void setVelocityViewExtension(String velocityViewExtension) {
		this.velocityViewExtension = velocityViewExtension.startsWith(".") ? velocityViewExtension
				: "." + velocityViewExtension;
	}

	/*
	 * 设置错误页面的默认路由信息
	 * 
	 */
	public void setError404View(String error404View) {
		errorViewMapping.put(404, error404View);
	}

	public void setError500View(String error500View) {
		errorViewMapping.put(500, error500View);
	}

	public void setError401View(String error401View) {
		errorViewMapping.put(401, error401View);
	}

	public void setError403View(String error403View) {
		errorViewMapping.put(403, error403View);
	}

	public void setErrorView(int errorCode, String errorView) {
		errorViewMapping.put(errorCode, errorView);
	}

	public String getErrorView(int errorCode) {
		return errorViewMapping.get(errorCode);
	}

	public Map<Integer, String> getErrorViewMapping() {
		return errorViewMapping;
	}

	public void setErrorViewMapping(Map<Integer, String> errorViewMapping) {
		this.errorViewMapping = errorViewMapping;
	}

	public void setUrlParaSeparator(String urlParaSeparator) {
		this.urlParaSeparator = urlParaSeparator;
	}

}
